package com.suanfa;


/**
 * @Author weijingchen
 * @Date 2025/5/28 21:26
 * @Version 1.0.0
 */
public class Test12 {
    public static void main(String[] args) {
        int sum = 0;
        int i = 0;
        int j=getSum(sum, i);
        System.out.println(j);

        System.out.println(getSum(100));

        System.out.println(getFactorial(5));

        System.out.println(getSum1(1));
    }

    //递归求和-自己写的
    private static int getSum(int sum, int i) {
        sum+=i;
        return i<100?getSum(sum,++i):sum;
    }


    private static int getSum1( int i) {
        return i<100?i+getSum1(++i):i;
    }

    //递归求和--教程里面的
    private static int getSum(int num) {
        if (num == 1){
            return 1;
        }
        return  num + getSum(num-1);
    }

    //递归求阶乘
    private static int getFactorial(int num) {
        if (num == 1){
            return 1;
        }
        return  num * getFactorial(num-1);
    }
}
